@echo off

set databaseName=%1
set userName=%2
set password=%3

set usage=Usage: setupdb databaseName username password. eg. setupdb arch arch arch
if "%databaseName%" == "" (
    echo %usage%
    exit /B 1
)
if "%userName%" == "" (
    echo %usage%
    exit /B 1
)
if "%password%" == "" (
    echo %usage%
    exit /B 1
)

set errorlevel=
db2 connect to %databaseName% user %userName% using %password%
if not "%errorlevel%" == "0" (
    echo invalid database name, user name or password
    exit /B 2
)

db2 -tvf ddl.01.bootstrap.sql -z setupdb.log

db2 -tvf ddl.02.user.sql -z setupdb.log

db2 -tvf ddl.03.archive.sql -z setupdb.log

db2 -tvf ddl.04.loan.sql -z setupdb.log

db2 -tvf dml.ad_config.sql -z setupdb.log

db2 -tvf dml.ar_archdef.sql -z setupdb.log

db2 -tvf dml.ar_archdef_operation.sql -z setupdb.log

db2 -tvf dml.ar_category.sql -z setupdb.log

db2 -tvf dml.ar_classification.sql -z setupdb.log

db2 -tvf dml.ar_dictionary.sql -z setupdb.log

db2 -tvf dml.ar_editability.sql -z setupdb.log

db2 -tvf dml.ar_field.sql -z setupdb.log

db2 -tvf dml.ar_archdef_field.sql -z setupdb.log

db2 -tvf dml.ar_officialword.sql -z setupdb.log

db2 -tvf dml.ar_operation.sql -z setupdb.log

db2 -tvf dml.ar_retention.sql -z setupdb.log

db2 -tvf dml.ar_security.sql -z setupdb.log

db2 -tvf dml.ar_stamp.sql -z setupdb.log

db2 -tvf dml.ar_stamp_field.sql -z setupdb.log

db2 -tvf dml.id_button.sql -z setupdb.log

db2 -tvf dml.id_module.sql -z setupdb.log

db2 -tvf dml.id_privilege.sql -z setupdb.log

db2 -tvf dml.id_role.sql -z setupdb.log

db2 -tvf dml.id_role_privilege.sql -z setupdb.log

db2 -tvf dml.ln_node_role.sql -z setupdb.log

db2 -tvf import.ar_template.sql -z setupdb.log

db2 terminate
